package com.example.rxpermissiondemo;

import android.app.ActivityManager;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import java.util.List;

public class BaseActivity extends AppCompatActivity {
    private static final String TAG = "BaseActivity";
    private boolean isActive = true;
    @Override
    protected void onStop() {
        super.onStop();
        Log.e(TAG, "onStop: isActive" + isActive);

        if (!Utils.isForeground(this)) {
            //app 进入后台
            //全局变量isActive = false 记录当前已经进入后台
            isActive = false;
        }
    }

    @Override
    protected void onResume() {
        Log.e(TAG, "onResume: isActive:" + isActive);
        super.onResume();

        if (!isActive) {
            //app 从后台唤醒，进入前台
            try {
                PermissionUtil.getInstance().mustBeGranted(this, PermissionUtil.REQUEST_PRIMISSION);
            } catch (Exception e) {
                e.printStackTrace();
            }
            isActive = true;
        }
    }




}

